package com.demo.homework;

public class Person {

    private String name;
    private int flag; //1 为男 0为 女
    private int age;
    private boolean isMarried; // true为结婚 false为未结婚

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isMarried() {
        return isMarried;
    }

    public void setMarried(boolean married) {
        isMarried = married;
    }

    public Person(String name, int flag, int age, boolean isMarried) {
        this.name = name;
        this.flag = flag;
        this.age = age;
        this.isMarried = isMarried;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", flag=" + flag +
                ", age=" + age +
                ", isMarried=" + isMarried +
                '}';
    }
    public static boolean marryWith(Person p1,Person p2){
        if(!(p1.isMarried&&p2.isMarried)){ //是否结婚
            if ((p1.flag^p2.flag)==1){ //是否异性
                if(p1.age>=20&&p2.age>=19||p2.age>=20&&p1.age>=19){
                    return true;
                }
            }
        }
        return false;
    }
    public void study(String school){
        System.out.println(this.name+"在"+school+"学校学习");
    }

    public static void main(String[] args) {
        Person p1 = new Person("张三", 1, 22, false);
        Person p2 = new Person("张三", 0, 19, false);
        boolean b = Person.marryWith(p1, p2);
        if(b){
            System.out.println("可以结婚");
        }else{
            System.out.println("不能");
        }

        Person person = new Person("张三", 1, 22, true) {
            @Override
            public void study(String school) {
                System.out.println(this.getName()+"在"+school+"学校学习了"+(this.getAge()-19)+"年");
            }
        };
        person.study("泉大");
    }
}
